package com.cloudlead.common.worker.interceptor;

import com.cloudlead.common.lang.api.ActionResponse;
import com.cloudlead.common.lang.api.ErrorActionResponse;
import com.cloudlead.common.lang.api.ErrorMeta;
import com.cloudlead.common.lang.api.SimpleActionResponse;
import com.cloudlead.common.lang.utils.ExceptionHelper;
import com.cloudlead.common.worker.ActionContext;
import com.cloudlead.common.worker.Interceptor;
import com.cloudlead.common.worker.InterceptorChain;
import com.cloudlead.common.worker.annotation.Order;
import com.cloudlead.common.worker.annotation.Provider;

/**
 * Created by Dean on 2015/6/3.
 */
@Provider
@Order(0)
public class ExceptionInterceptor implements Interceptor {
    @Override
    public void intercept(ActionContext actionConfig, InterceptorChain chain) {
        try {
            chain.process(actionConfig);
        } catch (Exception e) {
            ErrorActionResponse errorActionResponse = ExceptionHelper
                    .toResponse(e);
            actionConfig.setResponse(errorActionResponse);
            return;
        }
    }

}
